package com.shenmazong.servereduresume.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.shenmazong.servereduresume.dto.TbLevel;
import com.shenmazong.servereduresume.dto.TbPractice;
import com.shenmazong.servereduresume.dto.TbProject;
import com.shenmazong.servereduresume.mapper.TbProjectMapper;
import com.shenmazong.servereduresume.service.TbProjectService;
import com.shenmazong.utils.ResultResponse;
import com.shenmazong.vo.BatchChooseIdVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

/**
 *
 */
@Service
public class TbProjectServiceImpl extends ServiceImpl<TbProjectMapper, TbProject>
implements TbProjectService {
    @Autowired
    private TbProjectMapper tbProjectMapper;
    @Override
    public ResultResponse findByInformationId(BatchChooseIdVo batchChooseIdVo) {
        Object o = batchChooseIdVo.getParamMap().get("informationId");
        if (o==null){
            return ResultResponse.FAILED("非法参数");
        }
        List<TbProject> one = null;
        try {
            one = tbProjectMapper.selectList(new QueryWrapper<TbProject>().lambda().eq(TbProject::getInformationId, o)
                    .eq(TbProject::getDeleteFlag, 0));
        } catch (Exception e) {
            e.printStackTrace();
            return ResultResponse.FAILED();
        }
        return ResultResponse.SUCCESS(one);
    }

    @Override
    public ResultResponse saveOrUpdateProject(TbProject tbProject) {
        try {
            if (tbProject.getProjectId()==null) {
                tbProjectMapper.insert(tbProject);
            }else {
                tbProject.setUpdateTiem(new Date());
                tbProjectMapper.updateById(tbProject);
            }
        } catch (Exception e) {
            e.printStackTrace();
            return ResultResponse.FAILED();
        }
        return ResultResponse.SUCCESS();
    }

    @Override
    public ResultResponse deleteProject(BatchChooseIdVo batchChooseIdVo) {
        if (batchChooseIdVo.getIds().size()==0){
            return ResultResponse.FAILED("至少选择一个删除");
        }
        try {
            for (Long id : batchChooseIdVo.getIds()) {
                TbProject certificate = tbProjectMapper.selectById(id);
                certificate.setDeleteFlag((byte) 1);
                tbProjectMapper.updateById(certificate);
            }
        } catch (Exception e) {
            e.printStackTrace();
            return ResultResponse.FAILED();
        }
        return ResultResponse.SUCCESS();
    }
}




